<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta content="yes" name="apple-mobile-web-app-capable" />
<meta content="black" name="apple-mobile-web-app-status-bar-style" />
<meta content="telephone=no" name="format-detection" />
<meta content="email=no" name="format-detection" />
<title></title>
<link rel="stylesheet" href="../../css/s_plus.css" />
<link rel="stylesheet" href="../../css/base.css" />
<link rel="stylesheet" href="../../css/layout.css" />
<link rel="stylesheet" href="../../css/choice.css" />
<script type="text/javascript" src="../../libs/vue.js" ></script>
<script type="text/javascript" src="../../js/jquery.1.9.1.min.js" ></script>
<script type="text/javascript" src="../../js/app/url.js" ></script>
<script type="text/javascript" src="../../libs/hui.js" ></script>
<script type="text/javascript" src="../../js/app/api.js?time=201901092211"></script>
<script type="text/javascript" src="../../js/control/pop.js"></script>
<script type="text/javascript" src="../../js/md5.js"></script>
<script type="text/javascript" src="../../js/control/select/iosSelect.js"></script>
<link rel="stylesheet" href="../../js/control/select/iosSelect.css" />
<script type="text/javascript" src="../../js/control/swal/sweetalert.min.js"></script>
<link rel="stylesheet" href="../../js/control/swal/sweetalert.css" />


</head>
<body>
	
	<div id="wrapper">
		<header class="f_l maxbox subhead">
		  <a class="back" @click="back"><i class="iconfont">&#xe605;</i></a>
		  <h1>施工预约</h1>
		</header>
		<section class="f_l maxbox edit_list">
		  <h3>基础信息</h3>
		  
	

		  <ul>
		    <li>
		      <b>标题</b>
		      <p><input class="edit_txt" v-model="params.title" name="" type="text" ></p>
		    </li>
		    <li>
		      <b>开始时间</b>
		      <p><input class="edit_txt" readonly="readonly" id="startTime"  v-model="params.startTime" name="" type="text" ></p>
		    </li>
		    <li>
		      <b>结束时间</b>
		      <p><input class="edit_txt" readonly="readonly" id="endTime"  v-model="params.endTime" name="" type="text" ></p>
		    </li>
		    <li>
		      <b>施工地址</b>
		      <p><input class="edit_txt" v-model="params.address" name="" type="text" ></p>
		    </li>
		    <li>
		      <b>施工详情</b>
		      <p><input class="edit_txt" v-model="params.constructionDetail" name="" type="text" ></p>
		    </li>
		    <li>
		      <b>处理时间</b>
		      <p><input class="edit_txt" readonly="readonly"  v-model="params.constructionTime"  type="text" ></p>
		    </li>
		     

		    
		  </ul>
		  <ul>
		    <li>
		      <b>终端列表</b>
		      <p>  请选择 	
		      	<select    id="device"  multiple  list="schList" listKey="schId" listValue="schNm">
			     <option v-for="item in zdlist" :value="item.TERMIMAL_ID">{{item.TERMIMAL_CODE}}</option>
    			</select>
		      </p>
		    </li>
		  </ul>
		</section>
		<section class="f_l maxbox block" style="margin-top:-10px;">
		    <dd class="txt_list" style="margin-top:-20px;">
		    	
		      <p v-for="item in selectDevice"><em>设备编号：</em>{{item}}</p>
		      <!--<p><em>设备编号：</em>NO123436</p>
		      <p><em>设备编号：</em>NO12920fd6</p>
		      <p><em>设备编号：</em>kjhfO15456</p>
		      <p><em>设备编号：</em>Ngsgfs4456</p>-->
		    </dd>
		  </dl>
		</section>
		<section class="f_l maxbox mar_t mar_f t_c">
		  <a class="btn mian_btn" @click="submitData">提交</a>
		</section>

</div>


<script>

	
	var sp = new Vue({
			el:"#wrapper",
			data:{
				selectDevice:[],
				zdlist:[],
				
				params:{
					"companyId.id":"",
					title: "", 
					startTime: "", 
					endTime: "", 
					constructionTime:"",
					address:"",
					constructionState:"10",
					zdList:"",//4,5,6
					oldzdList:"",//1,2,3
					constructionDetail:"",
					"constructionUser.id":""
					}
			
			},
			
				mounted: function() {
//					console.log("最新时间"+apiManage.getNowFormat);
					this.params.constructionTime=apiManage.getNowFormat();
				},
			
			methods:{
				selectDate:function(){
					checkDate();
				},
				addDevice:function(){
				},
					geshi:function(param){
							return formatTime(param);
						},
						
					showState:function(param){
//								10-新建，20-已确认，30-已完成
							if(param=='10'){
								return "新建";
							}
							else if(param=='20'){
								return "已确认";
							}
							else{
								return "已完成";

							}
				},
						
				back:function(){
					hui.back();
				},
				timeChange:function(param){//时间自动补零
					
					var tmpA = param.split(" ");
					
					if(tmpA[0].length<10){
						var timeArray = tmpA[0].split("-");
						
						var readyArray = [];
						for(var i=0;i<timeArray.length;i++){
							var cell = timeArray[i];
							var finalTime = "";
							if(cell.length==1){
								finalTime+="0"+cell;
//								cell="0"+cell;
						readyArray.push(finalTime);
							}
							else{
//								finalTime+=cell;
								readyArray.push(cell);
							}
						}
//						console.log('readyArray--'+JSON.stringify(readyArray));
						
						var myDate = readyArray.join("-") +" "+tmpA[1];
						console.log('转化后时间-------'+myDate);
						return myDate;
					}
					
				},
				timeDiff:function(aTime,bTime){
						
				
					
				},
				
				submitData:function(){
					
//					console.log("all params-----------"+JSON.stringify(sp.params));
					
//					console.log("get now --"+apiManage.getNowYYMMDDHHMM());
								console.log("比较的两个时间 --"+this.timeChange(this.params.startTime) +" "+apiManage.getNowYYMMDDHHMM());

				//this.timeChange(this.params.startTime);

					if(this.params.title==null||this.params.title==''){
						hui.toast("请填写标题");
					  return;
					}

				else if(this.params.startTime==null||this.params.startTime==''){
//						swal("", "请填写开始时间", "warning");
												hui.toast("请填写开始时间");
					  return;
					}

					else if(this.timeChange(this.params.startTime)<apiManage.getNowYYMMDDHHMM()){
								console.log("get now --"+this.params.startTime +" "+apiManage.getNowYYMMDDHHMM());
								hui.toast("开始时间必须大于当前时间");
					  return;
					}

							
	
					else if(this.params.endTime==null||this.params.endTime==''){
						hui.toast("请填写结束时间");
					  return;
					}
					
					else if(this.timeChange(this.params.endTime)<this.timeChange(this.params.startTime)){
						hui.toast("结束时间必须在开始时间之后");
					  return;
					}
					else if(this.params.constructionTime==null||this.params.constructionTime==''){
//						
						hui.toast("请填写处理时间");

					  return;
					}
						
					else if(this.params.address==null||this.params.address==''){
//						swal("", "请填写施工地址", "warning");
							hui.toast("请填写施工地址");
					  return;
					}
						
					else if(this.params.constructionDetail==null||this.params.constructionDetail==''){
//						swal("", "请填写施工详情", "warning");
						hui.toast("请填写施工详情");
					  return;
					}
					
					else if(this.params.zdList==null||this.params.zdList==''){
					hui.toast("请选择终端");

					  return;
					}
					
					
					else{
						
					}
						
			
					save();
				}
				
			}
		});
		
		function save() {
	   	var path = urlManager.saveConstructionReservation();
	   	console.log(path);
	   	var username = localStorage.getItem("username");
	   	var sec = localStorage.getItem("sec_pwd");
	   	var time = apiManage.getNow();
	   	var key = "loginName=" + username + "&passWord=" + sec + "&time=" + time;
	   	console.log(key);
	   	var paramKey = hex_md5(key);
	   	
	   	$.ajax({
	   		type:"POST",
	   		url: path,
	   		data:sp.params,
	   		beforeSend: function(request) {
	   			request.setRequestHeader("loginName", username);
	   			request.setRequestHeader("time", time);
	   			request.setRequestHeader("sign", paramKey);
	   			//		            request.setRequestHeader("Content-Type","application/text");

	   		},
	   		success: function(result) {
	   			console.log("保存施工预约============================" + JSON.stringify(result));
//	   				 sp.zdlist=result.list;
				swal({
							  title: "保存成功",
							  text: "",
							  type: "success",
							  showCancelButton: false,
							  confirmButtonColor: "#DD6B55",
							  confirmButtonText: "确认",
							  cancelButtonText: "取消",
							  closeOnConfirm: true,
							  closeOnCancel: false
							},
							function(isConfirm){
							  if (isConfirm) {
									hui.open("order_list.html?time="+apiManage.getNow(), {}, true, {});	

//							    swal("Deleted!", "Your imaginary file has been deleted.", "success");
							  } else {
//								    swal("Cancelled", "Your imaginary file is safe :)", "error");
							  }
							});

				


	   		}
	   	});

	   }
	   
	   
	   
		
		
		loadZDList();
		//获取终端CODE列表
	   function loadZDList() {
	   	var path = urlManager.terminalList();
	   	console.log(path);
	   	var username = localStorage.getItem("username");
	   	var sec = localStorage.getItem("sec_pwd");
	   	var time = apiManage.getNow();
	   	var key = "loginName=" + username + "&passWord=" + sec + "&time=" + time;
	   	console.log(key);
	   	var paramKey = hex_md5(key);
	   	
	   	var readyParam= {cusId:apiManage.getCompanyId(),status:"0"};
	   	$.ajax({
	   				type:"POST",
	   		data: readyParam,
	   		url: path,
	   		beforeSend: function(request) {
	   			request.setRequestHeader("loginName", username);
	   			request.setRequestHeader("time", time);
	   			request.setRequestHeader("sign", paramKey);
	   			//		            request.setRequestHeader("Content-Type","application/text");

	   		},
	   		success: function(result) {
	   			console.log("终端列表下拉框============================" + JSON.stringify(result));
	   				 sp.zdlist=result.list;

	   		}
	   	});

	   }
	   
	   
	   
	   
	   	
	
	
	$(function(){
		
		//从用户登录信息中获取
		var companyId=localStorage.getItem("companyId");
		sp.params["companyId.id"]=companyId;
		var userid=localStorage.getItem("userid");
		sp.params["constructionUser.id"]=userid;
		
		
		$("#device").change(function(){
     		var deviceArray = new Array();

		$('#device :selected').each(function(i, selected) {
//				    realvalues[i] = $(selected).val();
//				    textvalues[i] = $(selected).text();
//			selectValues+=$(selected).val()+",";
//			deviceArray.push($(selected).val());
						deviceArray.push($(selected).text());

				});
				
			console.log(JSON.stringify(deviceArray));
			
			var param="";
			for(var i =0;i<deviceArray.length;i++){
				if(i==deviceArray.length-1){
					param+=deviceArray[i];
				}
				else{
					param+=deviceArray[i];
					param+=",";

				}
			}
			sp.params.zdList=param;
			console.log("sp.params.zdList:--- "+sp.params.zdList);
			sp.selectDevice=deviceArray;
	
});

settingDateControl("startTime");
settingDateControl("endTime");
settingDateControl("constructionTime");


function settingDateControl(pid){
	
	var selectDateDom = $('#'+pid);
    var showDateDom = $('#showDate');
    // 初始化时间
    var now = new Date();
    var nowYear = now.getFullYear();
    var nowMonth = now.getMonth() + 1;
    var nowDate = now.getDate();
    selectDateDom.attr('data-year', nowYear);
    selectDateDom.attr('data-month', nowMonth);
    selectDateDom.attr('data-date', nowDate);
    // 数据初始化
    function formatYear (nowYear) {
        var arr = [];
        for (var i = nowYear - 5; i <= nowYear + 5; i++) {
            arr.push({
                id: i + '',
                value: i + '年'
            });
        }
        return arr;
    }
    function formatMonth () {
        var arr = [];
        for (var i = 1; i <= 12; i++) {
        	
            arr.push({
                id: i + '',
                value: i + '月'
            });
        }
        return arr;
    }
    function formatDate (count) {
        var arr = [];
        for (var i = 1; i <= count; i++) {
        
            arr.push({
                id: i + '',
                value: i + '日'
            });
        }
        return arr;
    }
    var yearData = function(callback) {
    	
        callback(formatYear(nowYear))
    }
    var monthData = function (year, callback) {
        callback(formatMonth());
    };
    var dateData = function (year, month, callback) {
        if (/^(1|3|5|7|8|10|12)$/.test(month)) {
            callback(formatDate(31));
        }
        else if (/^(4|6|9|11)$/.test(month)) {
            callback(formatDate(30));
        }
        else if (/^2$/.test(month)) {
            if (year % 4 === 0 && year % 100 !==0 || year % 400 === 0) {
                callback(formatDate(29));
            }
            else {
                callback(formatDate(28));
            }
        }
        else {
            throw new Error('month is illegal');
        }
    };
    var hourData = function(one, two, three, callback) {
        var hours = [];
        for (var i = 0,len = 24; i < len; i++) {
        	if(i<10){
        		i="0"+i;
        	}
            hours.push({
                id: i,
                value: i + '时'
            });
        }
        callback(hours);
    };
    var minuteData = function(one, two, three, four, callback) {
        var minutes = [];
        for (var i = 0, len = 60; i < len; i++) {
        	if(i<10){
        		i="0"+i;
        	}
            minutes.push({
                id: i,
                value: i + '分'
            });
        }
        callback(minutes);
    };
    selectDateDom.bind('click', function () {
        var oneLevelId = selectDateDom.attr('data-year');
        var twoLevelId = selectDateDom.attr('data-month');
        var threeLevelId = selectDateDom.attr('data-date');
        var fourLevelId = selectDateDom.attr('data-hour');
        var fiveLevelId = selectDateDom.attr('data-minute');
        var iosSelect = new IosSelect(5, 
            [yearData, monthData, dateData, hourData, minuteData],
            {
                title: '地址选择',
                itemHeight: 35,
                itemShowCount: 9,
                oneLevelId: oneLevelId,
                twoLevelId: twoLevelId,
                threeLevelId: threeLevelId,
                fourLevelId: fourLevelId,
                fiveLevelId: fiveLevelId,
                callback: function (selectOneObj, selectTwoObj, selectThreeObj, selectFourObj, selectFiveObj) {
                    selectDateDom.attr('data-year', selectOneObj.id);
                    selectDateDom.attr('data-month', selectTwoObj.id);
                    selectDateDom.attr('data-date', selectThreeObj.id);
                    selectDateDom.attr('data-hour', selectFourObj.id);
                    selectDateDom.attr('data-minute', selectFiveObj.id);
//                  showDateDom.html(selectOneObj.value + ' ' + selectTwoObj.value + ' ' + selectThreeObj.value + ' ' + selectFourObj.value + ' ' + selectFiveObj.value);
var  params= selectOneObj.value + '' + selectTwoObj.value + '' + selectThreeObj.value + '' + selectFourObj.value + '' + selectFiveObj.value;
					console.log(params);
					params=params.replace("年","-");
					params=params.replace("月","-");
					params=params.replace("日"," ");
					params=params.replace("时",":");
					params=params.replace("分","");

					sp.params[pid]=params;
                }
        });
    });
   
}
   	
	


	
	});

	
</script>
</body>
</html>